//================v2要点总结===============
/**
 * 针对v1进行的优化
 * 1.借助nums来记录已用过的数据，节省一些空间
 */

/**
 * @param {number[]} nums
 * @return {number[][]}
 */
var permute = function (nums) {
    let n = nums.length
    let tmp = new Array(n).fill(0)
    let rslt = []

    function dfs(index, len) {
        if (len === n) {
            rslt.push([...tmp])
            return
        }
        for (let i = 0; i < n; i++) {
            if (nums[i] !== -11) {
                tmp[index] = nums[i]
                nums[i] = -11
                dfs(index + 1, len + 1)
                nums[i] = tmp[index]
            }
        }
    }
    dfs(0, 0)
    return rslt
};


console.log(permute([1, 2, 3]))